<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例 - vue实现列表增加和删除</title>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
</head>
<body>
<div id="app">
 <input v-model="newAddText" placeholder="请输入要添加的内容" />
	<button @click='addNewList'>添加</button>
	<ul>
		<li  v-for='(list,index) in lists' v-bind:key='list.id'>
			{{list.title}}  <button v-on:click='lists.splice(index, 1)'>删除</button>
		</li>
	</ul>
</div>
 
<script>
 
var vm = new Vue({
  el: '#app',
  data: {
  newAddText:'',
	  lists:[
		  {id:1,title:'手机号码'},
		  {id:2,title:'qq号'},
		  {id:3,title:'姓名'},
	  ],
	  nextTodoId: 4
  },
  methods:{
	  addNewList:function(){
		  this.lists.push({
			  id:this.nextTodoId++,
			  title:this.newAddText
		  })
		  this.newAddText=''
	  }
  }	
})
 
</script>
</body>
</html>
